<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ include file="../common/base.jsp"%>

<!DOCTYPE html>
<html lang="zh-CN">
<head>

<meta http-equiv="X-UA-Compatible" content="IE=10" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>部门管理系统</title>
<link href="${path }/dist/css/bootstrap.min.css" rel="stylesheet" />
<link href="${path }/dist/css/Buttom.css" rel="stylesheet" />


</head>
<body>
	<div class="panel panel-info">
	
		<div class="panel-heading" >
		
			<div class="btn-group" id="button_group1" >
				<button class="btn btn-default" type="button" onclick="window.location.href='${path}/downfile/downstencil'">模版下载</button>
				<button class="btn btn-default" type="button"
				data-toggle="modal" data-target="#upload" >上传部门</button>
				
				<button class="btn btn-default" type="button" onclick="window.location.href='${path}/downfile/dataexport'">导出部门</button>
				<button class="btn btn-default" type="button" data-toggle="modal"
					data-target="#addTreeNode"
					onclick="formtitleadd()">添加</button>
				<button class="btn btn-default" type="button" onclick="modify()"
				data-toggle="modal" data-target="#addTreeNode" >修改</button>
				<button class="btn btn-default" type="button"
					onclick="deleteDeptTreeNode()">删除</button>
				<button class="btn btn-default" type="button"
					onclick="window.parent.frames['menu'].refTreeNode()">刷新</button>
				<button class="btn btn-default" type="button" disabled="disabled">请点击相应的按钮进行操作</button>

			</div>
			
		</div>
		<div class="panel-body">
		<div class="table-responsive">
			<table class="table table-hover " >
				<tbody>
				
					<tr>
						<td
							style="text-align: right; border-right: 1px solid #ddd; width: 200px;">部门编号:</td>
						<td style="text-align: left;" id="deptno">${dept.deptno==null?"":dept.deptno }</td>
					</tr>
					<tr>
						<td
							style="text-align: right; border-right: 1px solid #ddd; width: 200px;">部门名称:</td>
						<td style="text-align: left;" id="deptname">${dept.deptname==null?"":dept.deptname }</td>
					</tr>
					<tr>
						<td
							style="text-align: right; border-right: 1px solid #ddd; width: 200px;">部门助记符:</td>
						<td style="text-align: left;" id="deptabb">${dept.deptabb==null?"":dept.deptabb }</td>
					</tr>
					<tr>
						<td
							style="text-align: right; border-right: 1px solid #ddd; width: 200px;">部门负责人:</td>
						<td style="text-align: left;" id="deptpic">${dept.deptpic==null?"":dept.deptpic }</td>
					</tr>
					<tr>
						<td
							style="text-align: right; border-right: 1px solid #ddd; width: 200px;">部门属性:</td>
						<td style="text-align: left;" id="deptp">${dept.deptp==null?"":dept.deptp }</td>
					</tr>
				</tbody>

			</table>
			</div>
			<div class="row" style="width: 150px;position: relative;left: 100px;display: none;" id="button_group2" >
				<button type="button" class="btn btn-default" onclick="Confirmedit()">确认修改</button>
				<button type="button" class="btn btn-default" onclick="Canceledit()">取消</button>
			</div>
		</div>
	</div>
	<div class="modal fade " role="dialog" aria-labelledby="uploadMenu" id="upload"
	tabindex="-1" aria-hidden="true">
				<div class="modal-dialog ">
				<div class="modal-content ">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="fileupload">上传</h4>
				</div>
				<div class="modal-body">
					<form class="form-horizontal" id="openfile" action="${path}/openfile/upload" method="post" enctype="multipart/form-data"
					 target="_parent">
					    <div class="form-group">
          					<label class="col-sm-4 control-label">文件路径：</label>

          					<!-- File Upload -->
          					<div class="col-sm-8">
            					<input  id="fileInput" type="file" name="file">
            					<p class="help-block">文件大小请勿超过5M</p>
         					</div>
        				</div>
        				<input type="hidden" name="seclectid" value="" id="hidden_seclectid">
					</form>
					</div>
					<div class="modal-footer" id="button_group5">
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					<button type="button" class="btn btn-primary" onclick="uploadFile()">upload</button>
				</div>
				</div>
				
		</div>
	</div>
	<div class="modal fade bs-example-modal-sm" id="addTreeNode"
		tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
		aria-hidden="true">
		<div class="modal-dialog modal-sm">
			<div class="modal-content " style="width: 298px">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal"
						aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title" id="myModalLabel"></h4>
				</div>
				<div class="modal-body">

					<form class="form-horizontal" id="NewTree"
						action="${path}/Department/adddeptTree" method="post">
						
							<div class="form-group">
								<!-- Text input-->
								<label class="col-sm-4 control-label" for="input01">部门编号</label>
								<div class="col-sm-8">
									<input type="text" placeholder="No：" class="form-control"
										name="dept.deptno">
									<p class="help-block">请输入部门编号</p>
								</div>
							</div>
							<div class="form-group">
								<!-- Text input-->
								<label class="col-sm-4 control-label" for="input01">部门名称</label>
								<div class="col-sm-8">
									<input type="text" placeholder="name：" class="form-control"
										name="dept.deptname">
									<p class="help-block">请输入部门名称</p>
								</div>
							</div>
							<div class="form-group">
								<!-- Text input-->
								<label class="col-sm-4 control-label" for="input01">助记符</label>
								<div class="col-sm-8">
									<input type="text" placeholder="Mnemonic" class="form-control"
										name="dept.deptabb">
									<p class="help-block">请输入助记符</p>
								</div>
							</div>
							<div class="form-group">
								<!-- Text input-->
								<label class="col-sm-4 control-label" for="input01">负责人</label>
								<div class="col-sm-8">
									<input type="text" placeholder="Person in charge"
										class="form-control" name="dept.deptpic">
									<p class="help-block">请输入负责人</p>
								</div>
							</div>
							<div class="form-group">

								<!-- Textarea -->
								<label class="col-sm-4 control-label">请输入部门属性</label>
								<div class="col-sm-8">
									<div class="textarea">
										<textarea class="form-control" name="dept.deptp" id="deptp"></textarea>
									</div>
								</div>
							</div>
							<input type="hidden" name="pid" value="" id="hidden_pid">
							<input type="hidden" name=isparent value="" id="hidden_isparent">
						
					</form>

				</div>
				<div class="modal-footer" id="button_group3" style="display: none;">
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					<button type="button" class="btn btn-primary"
						onclick="submitNewTree()">Add</button>
				</div>
				<div class="modal-footer" id="button_group4" style="display: none;">
					<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
					<button type="button" class="btn btn-primary"
						onclick="Confirmedit()">Edit</button>
				</div>
			</div>
		</div>
	</div>

	<script src="${path }/dist/js/jquery.min.js"></script>
	<script src="${path }/dist/js/bootstrap.min.js"></script>
	<script type="text/javascript">
	<!--		
	var deptnamet,
	deptabbt,
	deptpict,
	deptpt; //保存原先的值
	
	var deptname; //保存元素
	var deptabb;
	var deptpic;
	var deptp;

	//弹出修改窗口
	function uploadFile(){
		//var nodes = window.parent.frames['menu'].getTreeNode();
		//$("#hidden_seclectid").val(nodes.id);//返回 页面返回
		$("#openfile").submit();
	}
	function modify(){
		$('#myModalLabel').html("修改");
		var nodes = window.parent.frames['menu'].getTreeNode();
		$("#hidden_isparent").val(nodes.isParent);
		$("#NewTree").attr('action','${path}/Department/editdeptTree');
		//传值
		$("input[name='dept.deptno']").attr("readonly","readonly");
		$("input[name='dept.deptno']").val($("#deptno").text());
		$("input[name='dept.deptname']").val($("#deptname").text());
		$("input[name='dept.deptabb']").val($("#deptabb").text());
		$("input[name='dept.deptpic']").val($("#deptpic").text());
		$("input[name='dept.deptp']").val($("#deptp").text());
		//修改button 组
		$('#button_group3').hide();
		$('#button_group4').show();
		//alert($("#NewTree").attr('action'));
		

	}
	//弹出添加窗口
	function formtitleadd(){
		//获取父id
		$("#NewTree").attr('action',"${path}/Department/adddeptTree");
		$('#hidden_pid').val(window.parent.frames['menu'].getTreeNode().id);
		$('#myModalLabel').html("添加");
		
		$("input[name='dept.deptno']").removeAttr("readonly");
		//传值
		$("input[name='dept.deptno']").val("");
		$("input[name='dept.deptname']").val("");
		$("input[name='dept.deptabb']").val("");
		$("input[name='dept.deptpic']").val("");
		$("input[name='dept.deptp']").val("");
		
		//修改button 组
		$('#button_group3').show();
		$('#button_group4').hide();
		
	}
	
	//修改
	function Confirmedit(){
		//表单验证
			if ($("input[name='dept.deptname']").val() == null
					|| $("input[name='dept.deptname']").val() == "") {
				alert("name不能为空");
				$("input[name='dept.deptname']").focus();
				return ;
			}
		//alert($("input[name='dept.deptname']").val());
			//alert($("#NewTree").serialize());
			$("#NewTree").submit();
		
	}
		function deleteDeptTreeNode() {
			var nodes = window.parent.frames['menu'].getTreeNode();
			if (nodes != null) {
				if(nodes.id==0){
					alert("不能删除根节点");
					return ;
				}else if (!window.confirm('确认删除：' + nodes.id + ":" + nodes.name
						+ " 吗")) {
					return;
				}
				if(nodes.isParent){
					if (!window.confirm(nodes.id + ":" + nodes.name
							+ "为父节点，将删除它的所有子节点")) {
						return;
					}
				}
				var nextnodes=nodes.getNextNode()==null?nodes.getPreNode():nodes.getNextNode();
				if(null==nextnodes) nextnodes=nodes.getParentNode();
				var nodesparent=nodes.getParentNode();
				
				var url="?id="+nodes.id+"&nexid="+nextnodes.id+"&isparent="+nodes.isParent+"&parent="+nodesparent.id;
				//alert(url);
				window.location.href="${path}/Department/deleteeptTree"+url;
			}

		}
		
		function submitNewTree() {
			if ($("input[name='dept.deptno']").val() == null
					|| $("input[name='dept.deptno']").val() == "") {
				alert("id不能为空");
				$("input[name='dept.deptno']").focus();
				return ;
			} else if ($("input[name='dept.deptname']").val() == null
					|| $("input[name='dept.deptname']").val() == "") {
				alert("name不能为空");
				$("input[name='dept.deptname']").focus();
				return ;
			} else if ($("#hidden_pid").val() == null
					|| $("#hidden_pid").val() == "") {
				alert("请选择一个父项");
				return ;
			}
			var isNum = /^[0-9]*$/;
			if (!isNum.test($("input[name='dept.deptno']").val())) {
				alert("请输入数字");
				$("input[name='dept.deptno']").focus();
				return ;
			}
			$(function() {
				$.ajax({
					async : false,
					cache : false,
					type : 'POST',
					dataType : "html",
					url : '${path}/Department/isIDRepeat?id='
							+ $("input[name='dept.deptno']").val(),
					success : function(data) {
						//alert(data);
						if ("0" == data[0]) {
							alert("id 已存在");
							return;
						} else {
							/*var text = {
								id : $("input[name='dept.deptno']").val(),
								name : $("input[name='dept.deptname']").val(),
								abb : $("input[name='dept.deptabb']").val(),
								pic : $("input[name='dept.dept.deptpic']")
										.val(),
								content : $("#hidden_pid").val(),
								pid : $("#hidden_pid").val()
							};*/
							//alert(text.id);
							var nodes = window.parent.frames['menu'].getTreeNode();
							$("#hidden_isparent").val(nodes.isParent);//判断是否父节点
							//window.parent.frames['menu'].addTreeNode(text,$("#NewTree").serialize());
							$("#NewTree").submit();
						}
					},
					error : function() {
						alert("请求失败");
						return;
					}
				});
			})
		}
		

	//-->
	</script>

	<c:if test="${refDeptTreeNode != null&& refDeptTreeNode==true}">
		<script>
		<!--
			//是否刷新树
			window.parent.frames['menu'].refTreeNode()
			//alert('${tip}');
			//window.parent.frames['menu'].;
		//-->
		</script>
	</c:if>
	
	
		<c:if test="${refDeptparentTreeNode != null&& refDeptparentTreeNode==true}">
		<script>
		<!--
			//是否刷新树
			//alert(1);
			window.parent.frames['menu'].refparentTreeNode('${refDeptparentTreeNodeid}','${selecttree}');
			//alert('${tip}');
			//window.parent.frames['menu'].;
		//-->
		</script>
	</c:if>
	<c:if test="${tip != null }" >
	<script>
		alert('${tip}');
	</script>
</c:if>
	
</body>
</html>